package com.neusoft.mapper;

import com.neusoft.po.Food;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface FoodMapper {

    @Select("select * from food where businessId=#{businessId} order by foodId")
    public List<Food> listFoodByBusinessId(Integer businessId);


//    @Select("select * from food where foodId=#{foodId}")
//    Food getFoodByFoodId(Integer foodId)

    @Insert("INSERT INTO food (businessId, foodName, foodExplain, foodPrice, foodImg) " +
            "VALUES (#{businessId}, #{foodName}, #{foodExplain}, #{foodPrice}, #{foodImg})")
    int saveFood(@Param("businessId") Integer businessId,
                 @Param("foodName") String foodName,
                 @Param("foodExplain") String foodExplain,
                 @Param("foodPrice") Double foodPrice,
                 @Param("foodImg") String foodImg);

    @Update("UPDATE food SET businessId = #{businessId}, foodName = #{foodName}, " +
            "foodExplain = #{foodExplain}, foodPrice = #{foodPrice} WHERE foodId = #{foodId}")
    int updateFood(@Param("foodId") Integer foodId, @Param("businessId") Integer businessId,
                   @Param("foodName") String foodName,
                   @Param("foodExplain") String foodExplain,
                   @Param("foodPrice") Double foodPrice,
                   @Param("foodImg") String foodImg);

    @Delete("DELETE FROM food WHERE businessId = #{businessId} AND foodId = #{foodId}")
    int removeFood(@Param("businessId") Integer businessId, @Param("foodId") Integer foodId);


    @Select("select * from food where foodId=#{foodId}")
    Food getFoodById(Integer foodId);
}
